package queuedemo;

import java.util.Stack;

class MinStack {
    private Stack<Integer> s1;
    private Stack<Integer> minStack;

    public MinStack() {
         s1=new Stack<>();
        minStack=new Stack<>();

    }
    
    public void push(int val) {
        s1.push(val);
        if(minStack.empty()){
            minStack.push(val);
        }else{
            int x = minStack.peek();
            //一定要取等号否则会丢值
            if(val<=x){
                minStack.push(val);
            }
        }

    }
    
    public void pop() {
        int x = s1.pop();
        int x2 = minStack.peek();
        if(x==x2){
            minStack.pop();
        }

    }
    //得栈顶但不删除
    public int top() {
        return s1.peek();
    }
    
    public int getMin() {
        return minStack.peek();

    }
}